﻿using System;
using System.Collections.Generic;
using System.Text;
using TarreOA.TarreOADAL;
using TarreOA.TarreOAModels;

namespace TarreOA.TarreOABLL
{
    public class EmpEmailMappingtbService
    {
        //保存邮件发送信息
        public int saveEmailInfo(string suln, string iuln, string eContent,  DateTime sdt)
        {
            EmpEmailMappingtbDAO empEmailMappingtbDAO = new EmpEmailMappingtbDAO();
            int count = empEmailMappingtbDAO.saveSendEmailInfo(suln, iuln, eContent, sdt);
            return count;
        }

        //根据发件人查询邮件信息
        public List<EmpEmailMappingtb> findBySendUserLoginName(string suln)
        {
            EmpEmailMappingtbDAO empEmailMappingtbDAO = new EmpEmailMappingtbDAO();
            return empEmailMappingtbDAO.findBySendUserLoginName(suln);
        }

        //根据收件人查询邮件信息
        public List<EmpEmailMappingtb> findByInceptUserLoginName(string iuln)
        {
            EmpEmailMappingtbDAO empEmailMappingtbDAO = new EmpEmailMappingtbDAO();
            return empEmailMappingtbDAO.findByInceptUserLoginName(iuln);
        }

        //根据邮件编号查询邮件信息
        public EmpEmailMappingtb findByEmpEmailId(int eid, string state)
        {
            EmpEmailMappingtbDAO empEmailMappingtbDAO = new EmpEmailMappingtbDAO();
            return empEmailMappingtbDAO.findByEmpEmailId(eid, state);
        }

        //根据邮件编号更改邮件阅读状态
        public bool updateEmailReadState(int eid, string st)
        {
            bool state = false;
            EmpEmailMappingtbDAO empEmailMappingtbDAO = new EmpEmailMappingtbDAO();
            if (empEmailMappingtbDAO.updateEmailInfo(eid, st) == 1)
            {
                state = true;
            }
            return state;
        }

        //根据邮件编号删除邮件信息
        public bool delEmailInfo(string[] eids, string st)
        {
            bool state = false;
            int count = 0;
            EmpEmailMappingtbDAO empEmailMappingtbDAO = new EmpEmailMappingtbDAO();
            for (int i = 0; i < eids.Length; i++)
            {
                if (empEmailMappingtbDAO.delEmailInfo(int.Parse(eids[i]), st) == 1)
                {
                    count++;
                }
            }
            if (count == eids.Length)
            {
                state = true;
            }
            return state;
        }
    }
}
